﻿var time_delay=null;
$(document).ready(function(){
	
	if ($("#VideoBanner")[0])
	{
		$.foucs({
			direction: 'right'
		});
	}
	$.fn.scroll_({arrows:false,mouseWheelSpeed: 30,verticalGutter:0});
	$('#Video_hudong .Tab2').Tab({lilab:"li",labselect:".change",Tabname:".Tab_nr",labaction:"click",animatename:"scroll_x",animateTime:300,mode:"none"})
	//分享
	$(".VideoHeader .btn_share").on("mouseenter",function(){
		$("#MobilePhoneWatch").hide()
		$("#VideoShare").toggle();	
	})
	//手机看直播 
	$(".VideoHeader .btn_livemobilephone").on("mouseenter",function(){
		$("#VideoShare").hide()
		$("#MobilePhoneWatch").toggle();	
	})
	
	$("#VideoShare").on("mouseleave",function(){
		$(this).hide()
		
	})
	
	//弹幕开关
	$(".btn_danmu").bind("click",function(){
		var btn_offon=$(this).find(".btn_offon")
		var txt=$(this).find("strong")
		if ($(this).is(".change"))
		{
			$(this).removeClass("change")
			$(this).css({"text-align":"right"})
			btn_offon.animate({"left":"0"},200)
			txt.text("弹幕开")
		}
		else
		{
			$(this).addClass("change");
			$(this).css({"text-align":"left"})
			btn_offon.animate({"left":"45px"},200)
			txt.text("弹幕关")
		}
		return false;
	})
	
	//礼物 显示与隐藏
	
	$(".btn_liwu").bind("click",function(){
		 var giftList=$("#giftList")
		 $(this).addClass("change");	
		
		giftList.fadeIn()
	})
	
	$("#MobilePhoneWatch").bind("mouseleave",function(){
		$(this).hide()	
		
	})
	$("#giftsend").bind("mouseleave",function(){
		$(this).hide()	
		$("#giftList li.change").removeClass("change")
	}).bind("mouseenter",function(){
clearTimeout(time_delay)	
		
	})
	
	
	
	$("#giftList li").bind("mouseenter",function(){
		clearTimeout(time_delay)	

		var giftwindow=$("#giftsend")
		var self=$(this)
		var giftpic=self.find("img").attr("src")
		var giftname=self.attr("data-name")
		var giftprice=self.attr("data-price")
		
		
		giftwindow.find(".photo img").attr("src",giftpic)
		giftwindow.find("h4 strong").text(giftname)
		giftwindow.find("h4 em").text("（"+giftprice+"L币）").attr("data-price",giftprice)
		giftwindow.find(".sl_select li").removeClass("change")
		giftwindow.find(".sl_select li:first").addClass("change");
		
		if ($(this).is(".change"))
		{
			$(this).removeClass("change")
			giftwindow.hide()
		}
		else
		{
			
					$(this).addClass("change").siblings().removeClass("change");
					giftwindow.show()
					
			
			
		}
		
		
	}).bind("mouseleave",function(){
			time_delay=setTimeout(function(){
						$("#giftsend").hide()	
						$("#giftList li.change").removeClass("change")
			},300)
	})
	
	//礼物数量选择
	$("#giftsend .sl_select li").bind("click",function(){
		$(this).addClass("change").siblings().removeClass("change");
	})
	
		$(".Video_").bind('mouseenter',function(){
					var self=$(this)
					time_delay=setTimeout(function(){
								if(!self.is(":animated"))
								{
									var btnplay=self.find(".btn_play")
									var img=self.find("img");
									self.addClass("star_animate");
									btnplay.stop(true,false).fadeIn(300)
									img.stop(true,false).animate({"opacity":0.6}, 500);
								}
						
					},100)
				
			}).bind('mouseleave',function(){
				    clearTimeout(time_delay)	
							var self=$(this)
							if (self.is(".star_animate"))
							{	
									var btnplay=self.find(".btn_play")
									var img=self.find("img");
									btnplay.stop(true,false).fadeOut(300)
									img.stop(true,false).animate({"opacity":1}, 500);
									self.removeClass("star_animate");
							}
			})	
	
	
	$(".Charform .text").key("发送弹幕","#333","#999")
	$("#gift_ly").key("礼物留言","#333","#999")
	
	
})
//输入关键词
	$.fn.key=function(a,color1,color2){
		var self=$(this)
		if (self.length==0) return false;
		if (!self.is("input") && !self.is("textarea")) return false;
		self.css("color",color2)
			var keywords=a;	
			self.val(keywords).bind("focus",function(){
				if (this.value==keywords){this.value="";this.style.color=color1}
			}).bind("blur",function(){
				if (this.value==""){this.value=keywords;this.style.color=color2}
			});
	}

//加载滚动条
$.fn.scroll_=function(config){
	var scrollobj=$("[data-scroll]")
	if (scrollobj.length==0) return false;
	scrollobj.each(function(index, element) {
			var self=$(this)
			if (self.length==0)  return false;

			var h=parseInt(self.attr("data-scroll-height")),
				w=parseInt(self.attr("data-scroll-width")),
				color=self.attr("data-scroll-color");
				self.css({"width":"100%"});
				self.wrap('<div class="container1" style="width:'+w+'px"></div>').wrap('<div class="div_scroll"></div>');
				self.parents('.div_scroll').css({height:h}).scroll_absolute(config)
				self.find("img").load(function(){self.parents('.div_scroll').scroll_absolute(config);})

			if (typeof(color)!="undefined")
			{setTimeout(function(){self.parents(".container1").find(".scroll_drag").css({"background":color})},500);}
	});
}

//选项卡切换
$.fn.Tab=function(config){
			var self=$(this);
			var select_=0;
			var classname=config.labselect.replace(".","")
			if (self.length==0) return false;
			if (self.find(config.lilab).length==0) return false;
			
			
			self.each(function(index, element) {
							
				self=$(this);
						
						if (self.find(config.labselect).length==0) 
						{self.find(config.lilab+":eq(0)").addClass(classname);}
						self.find(config.lilab).each(function(index, element) {
							if (!$(this).is(config.labselect))
							{
								self.siblings(config.Tabname+":eq("+index+")").hide();
							}
						});
						
						self.find(config.lilab).bind(config.labaction+".action",function(){
							
							var index=$(this).index();
							if(self.siblings(config.Tabname+":visible").is(":animated")){ 
							return false;
							
							}

							
							if ($(this).is(config.labselect)) return false;
							var index2=$(this).siblings(config.labselect).index()
							$(this).addClass(classname).siblings().removeClass(classname);
							
							config.animate(index,index2,config.animatename)
							return config.labaction=="click"?   false :  true;
						})
						
						config.animate=function(index,index2,active){
							
							switch (active)
							{
								case "fade":
									self.siblings(config.Tabname+":visible").hide();
									self.siblings(config.Tabname+":eq("+index+")").fadeIn(config.animateTime);
								break;
								case "scroll_x":
									self.parent().css({"position":"relative","overflow":"hidden"});
									var selfs=self.siblings(config.Tabname+":visible")
									var dr="100%",dr2="100%"
									if (index2>index)
									{
										dr="100%";
										dr2="-100%"
									}
									else
									{
										dr="-100%";
										dr2="100%"
									}
									var top=selfs.position().top
									
									
									if (config.mode=="delay")		
									{
									//当前渐隐
									selfs
									.css({"position":"relative","width":"100%"})
									.stop(true,false)
									.animate({"left":dr,"opacity":0},config.animateTime,
												function(){
													 $(this).css({"position":"static","left":"auto","opacity":1,"display":"none"}
												)}
											)
									setTimeout(function(){
												self.siblings(config.Tabname+":eq("+index+")").css({"position":"relative","left":dr2,"display":"block","opacity":0})
												.stop(true,false)
												.animate({"left":0,"opacity":1},config.animateTime
												,function(){
														$(this).css({"top":0,"position":"static"})	
														
												})
									},config.animateTime)		
								
									}
									
									else
									{
										
											selfs
											.css({"position":"absolute","width":"100%","left":selfs.position().left,"top":selfs.position().top})
											.stop(true,false)
											.animate({"left":dr,"opacity":0},config.animateTime,
												function(){
													 $(this).css({"position":"relative","top":"auto","left":"auto","opacity":1,"display":"none"}
												)}
											)
									
									
												self.siblings(config.Tabname+":eq("+index+")").css({"position":"relative","left":dr2,"display":"block","opacity":0})
												.stop(true,false)
												.animate({"left":0,"opacity":1},config.animateTime
												,function(){
														$(this).css({"top":0,"position":"relative"})	
														
												})
									}
								break;
								
								
								case "none":
									self.siblings(config.Tabname+":visible").hide();
									self.siblings(config.Tabname+":eq("+index+")").show();
								break;	
								
							}
							
							
						}


            });

		}